import random
import time

from apscheduler.schedulers.blocking import BlockingScheduler

from sign import init, start


def job():
    # 延迟随机时间执行
    randomValue = random.randint(0, 10)
    print("延迟", randomValue, "分钟执行！")
    time.sleep(randomValue * 60)

    print("开始执行任务！")
    init()
    start()


if __name__ == '__main__':
    bgsched = BlockingScheduler()

    bgsched.add_job(
        func=job, trigger='cron', day_of_week='1-5', hour=8, minute=25, id='00001', name='First job',
        jobstore='default', executor='default', replace_existing=True)

    bgsched.add_job(
        func=job, trigger='cron', day_of_week='1-5', hour=18, minute=1, id='00002', name='second job',
        jobstore='default', executor='default', replace_existing=True)

    print("定时器已启动!")
    # 启动调度
    bgsched.start()
